package com.jichangxiu.system.action;

import com.jichangxiu.common.entity.vo.PageResult;
import com.jichangxiu.system.entity.dto.query.QuerySysPower;
import com.jichangxiu.system.entity.vo.SysPowerVo;
import com.jichangxiu.system.service.SysPowerService;
import com.jichangxiu.framework.action.BaseAction;
import com.jichangxiu.common.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * SysPowerAction:
 *
 * @author JiChangXiu
 * @create 2024-06-28 13:44:36
 */
@Slf4j
@Rest("/system/power")
@Tag(name = "系统权限控制器")
public class SysPowerAction extends BaseAction {

    @Resource
    private SysPowerService sysPowerService;

    /**
     * 根据主键查询系统权限
     *
     * @param id       系统权限主键
     * @param isExtend 是否扩展
     * @return 系统权限详情
     */
    @Get("/{id}")
    @Operation(summary = "根据主键查询系统权限")
    @PreAuthorize("@jcx.hasPower('system:power:info')")
    public SysPowerVo info(@PathVariable("id") @NotBlank(message = "主键不能为空") String id, @RequestParam(value = "isExtend", required = false, defaultValue = "false") Boolean isExtend) {
        return sysPowerService.info(id, isExtend);
    }

    /**
     * （可分页）查询系统权限列表
     *
     * @param querySysPower 查询视图对象
     * @return （分页）系统权限列表
     */
    @Get("/lists")
    @Operation(summary = "（可分页）查询系统权限列表")
    @PreAuthorize("@jcx.hasPower('system:power:lists')")
    public PageResult lists(@ParameterObject QuerySysPower querySysPower) {
        return pageResult(sysPowerService.lists(querySysPower));
    }

}